package cate.common.table.activity.firstpay.item;

import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@NoteClass(value = "超值首充-奖励配置")
public class SuperFirstPayItemRow extends ERow {
    @NoteField(value = "档位")
    public Integer level;
    @NoteField(value = "登录天数")
    public Integer day;
    @NoteField(value = "奖励")
    public String rewardStr;
    @NoteField(value = "种族印记")
    public String campMarkStr;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        id = xrw.getInteger("ID");
        level = xrw.getInteger("档位");
        day = xrw.getInteger("登录天数");
        rewardStr = xrw.getString("奖励");
        campMarkStr = xrw.getString("种族印记");
    }

    @NoteField("奖励位置->种族印记")
    public Map<Integer, Byte> campMarks = new HashMap<>();

    @Override
    public void decode() {
        super.decode();
        if (StringUtils.isNotBlank(campMarkStr)) {
            try {
                String[] splits = campMarkStr.split("#");
                for (String subStr : splits) {
                    String[] subSplits = subStr.split(":");
                    int pos = Integer.parseInt(subSplits[0]);
                    byte camp = Byte.parseByte(subSplits[1]);
                    campMarks.put(pos, camp);
                }
            } catch (Exception e) {
                log.error("解析种族印记失败!", e);
            }
        }
    }
}
